<!DOCTYPE html>
{% load static i18n %}
<html lang="zh-hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改用户信息 - 我的博客</title>
    <link rel="stylesheet" href="{% static 'users/bulma.css' %}">
    <link rel="stylesheet" href="{% static 'users/style.css' %}">
    <script src="{% static 'users/js/all.min.js' %}"></script>
    <style>
        .form-container {
            max-width: 800px;
            margin: 2rem auto;
            padding: 2rem;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
        .field-horizontal {
            margin-bottom: 1.5rem;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar is-primary">
        <div class="container">
            <div class="navbar-brand">
                <a class="navbar-item" href="/">
                    <strong>我的博客</strong>
                </a>
            </div>
            <div class="navbar-menu">
                <div class="navbar-end">
                    <div class="navbar-item">
                        <div class="buttons">
                            <a href="{% url 'users:user_info' %}" class="button is-light">
                                返回个人中心
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="container">
        <div class="form-container">
            <h2 class="title is-3 has-text-centered mb-5">修改用户信息</h2>

            <!-- 只读用户名 -->
            <div class="field-horizontal">
                <div class="field">
                    <label class="label">用户名</label>
                    <div class="control has-icons-left">
                        <input class="input" type="text" value="{{ user.username }}" readonly>
                        <span class="icon is-small is-left">
                            <i class="fas fa-user"></i>
                        </span>
                    </div>
                </div>
            </div>

            <!-- 编辑表单 -->
            <form method="post" enctype="multipart/form-data">
                {% csrf_token %}
                
                <!-- 邮箱字段 -->
                <div class="field-horizontal">
                    <div class="field">
                        <label class="label">{{ form.email.label }}</label>
                        <div class="control">
                            {{ form.email }}
                            {% if form.email.errors %}
                            <p class="help is-danger">{{ form.email.errors }}</p>
                            {% endif %}
                        </div>
                    </div>
                </div>

                <!-- 用户资料字段 -->
                {% for field in user_profile_form %}
                <div class="field-horizontal">
                    <div class="field">
                        <label class="label">{{ field.label }}</label>
                        <div class="control">
                            {{ field }}
                            {% if field.errors %}
                            <p class="help is-danger">{{ field.errors }}</p>
                            {% endif %}
                        </div>
                    </div>
                </div>
                {% endfor %}

                <!-- 表单操作 -->
                <div class="field is-grouped is-grouped-centered mt-6">
                    <div class="control">
                        <button type="submit" class="button is-primary is-medium">
                            <i class="fas fa-save mr-2"></i>保存修改
                        </button>
                    </div>
                    <div class="control">
                        <a href="{% url 'users:user_info' %}" class="button is-light is-medium">
                            取消返回
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="content has-text-centered">
            <p>© 2025 我的博客 版权所有</p>
        </div>
    </footer>

    <!-- 脚本 -->
    <script>
        // 图片预览功能
        document.getElementById('id_image').addEventListener('change', function(e) {
            const reader = new FileReader();
            reader.onload = function() {
                document.querySelector('.avatar-preview').src = reader.result;
            }
            reader.readAsDataURL(e.target.files[0]);
        });
    </script>
</body>
</html>